<template>
  <!-- 分公司印章管理 -->
  <base-breadcrumb :title="$route.meta.title">
    <!-- 搜索 -->
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <!-- 表格 -->
    <a-card :bordered="false">
      <!-- <title-name :title="$route.meta.title" /> -->
      
      <!--v-btnPermission="'lu_0014_exp_06'"-->
      <!-- <excel
        ref="exportAll"
        class="ml12"
        file-name="西南公司印章"
        is-click-generate="false"
      >
        <a-button
          slot="excelBtn"
          type="primary"
          icon="download"
          :loading="loading"
          @click="exportAll"
        >
          导出
        </a-button>
      </excel> -->
      <!-- 表格 -->
      <list-table
        ref="table"
        row-key="id"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        :export-config="{ use: true, select: '西南公司印章', all: '西南公司印章' }"
      >
      <a-button
        slot="prefix"
        slot-scope="ref"
        v-btnPermission="'oa_011_add_01'"
        class="mb12"
        icon="plus"
        type="primary"
        @click="handleManage(2)"
      >
        新增
      </a-button>
      <span
          slot="index"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <template
          slot="action"
          slot-scope="text, record"
        >
          <a @click="handleManage(0, record)">查看</a>
          <span v-if="record.creatorId == id">
            <a-divider type="vertical" />
            <a @click="handleManage(1, record)">编辑</a>
          </span>
          <!-- <a-divider type="vertical"></a-divider> -->
          <!-- <a class="del_btn" @click="handleRemove(record)">删除</a> -->
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
  // import { STable } from '@/components' // 表格
  import { getList, remove, getLabels } from '@/api/office/sealManage/filialeSealManage' // api
  import SelectCompanyAndProject from '@/components/Select/SelectCompanyAndProject.vue'
  import Selector from '@/components/Select/Selector'
  import BasePage from '@/views/basePage' // 基础配置
  import OrgTreeSelect from '@/components/OrgTreeSelect'

  const searchArr = [
    // 搜索框
    // {
    //   name: '单位',
    //   type: SelectCompanyAndProject,
    //   valueKey: 'unitId',
    // },
    {
      name: '所属单位',
      valueKey: 'searchQuery',
      type: OrgTreeSelect,
    },
    {
      name: '印章名称',
      type: 'input',
      value: 'title',
    },
  ]
  const columns = [
    {
      title: '序号',
      width: 80,
      dataIndex: 'index',
      scopedSlots: { customRender: 'index' }
    },
    {
      title: '单位名称',
      dataIndex: 'unitName',
      width: 220
    },
    {
      title: '印章名称',
      dataIndex: 'title',
      width: 220
    },
    {
      title: '保管部门',
      dataIndex: 'careDepartmentName',
      width: 220
    },
    {
      title: '保管人',
      dataIndex: 'careName',
      width: 120
    },
    {
      title: '联系电话',
      dataIndex: 'phone',
      width: 120
    },
    {
      title: '印章状态',
      dataIndex: 'statusName',
      width: 120
    },
    {
      title: '操作',
      dataIndex: 'action',
      width: '180px',
      align: 'center',
      scopedSlots: { customRender: 'action' },
    },
  ]
  export default {
    name:'a'+Date.now(),

    extends: new BasePage(),
    components: {
      // STable,
    },
    data() {
      this.columns = columns
      this.searchArr = searchArr
      return {
        loading:false,
        queryParam: {}, // 查询参数
        totalSize: null,
        id: JSON.parse(sessionStorage.getItem('ycloud-user_info'))?.employee?.userId, //登录人id
        loadData: (parameter) => {
          const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
          return getList(requestParameters).then((res) => {
            this.totalSize = res.totalSize
            return res
          })
        },// 加载数据方法 必须为 Promise 对象
        editModel: 0,
      }
    },
    computed: {
    },
    watch:{
    },
    created(){
    },
    methods: {
      // 搜索
      search(value) {
        value && (this.queryParam = value)
        this.$refs.table.refresh(true)
      },
      // 删除
      handleRemove(e){
        this.$confirm({
          title: '温馨提示',
          content: `确认删除${e.title}？`,
          onOk: () => {
            return remove(e.id).then(() => {
              this.$message.success('删除成功！')
              this.search()
            })
          },
        })
      },
      // 操作栏
      handleManage(type, record) {
        this.editModel = type
        let query = {
          editModel: type,
        }
        if (record && record.id) {
          query.id = record.id
        }
        this.$router.push({
          path: '/sealManagement/filialeSealManage/add',
          query,
        })
      },
      /**
       * 导出
       */
      exportAll() {
        this.loading = true
        let searchData = Object.assign(
          {
            pageSize: this.totalSize,
            pageNo: 1,
          },

          this.queryParam
        )
        getList(searchData)
          .then((res) => {
            res.data.forEach((item, index) => {
              item.index = index
            })
            this.loading = false
            this.$refs.exportAll.setDataAndGenerate(res.data)

            this.$message.success('导出成功')
          })
          .catch(() => {
            this.loading = false
          })
      },

    },
    mounted() {
      // this.$refs.exportAll.tableToExcelFile(this.$refs.table)
    },
  }
</script>
